// SchemaDesigner.h
#pragma once

#include <windows.h>
#include <CommCtrl.h>  // For TreeView

#include <nlohmann/json.hpp>
#include <string>
#include <vector>

using nlohmann::json;

class CSchemaDesigner {
 public:
  CSchemaDesigner(HINSTANCE hInstance, HWND hParent);
  void Show();

 private:
  // Dialog Procedure
  static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam,
                                  LPARAM lParam);

  // Initialization
  void OnInitDialog(HWND hDlg);

  // Data handling
  void LoadSchema();
  void SaveSchema();
  void ValidateSchema();
  void PopulateTree();
  void PopulateProperties(HTREEITEM hItem);
  void ClearProperties();
  void ApplyChanges();
  void AddNewItem(const std::string& type);
  void DeleteSelectedItem();

  // UI Helpers
  void SetControlState(BOOL isItemSeleted);

 private:
  HINSTANCE h_instance_;
  HWND h_parent_;
  HWND h_dialog_ = NULL;
  HWND h_tree_ = NULL;

  // Data
  json schema_json_;
  json meta_schema_json_;

  // State
  HTREEITEM h_selected_item_ = NULL;

  // Dynamically created property edit controls
  std::vector<HWND> property_labels_;
  std::vector<HWND> property_edits_;
};
